/**
 * Copyright (C) 2008 aileron.cc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cc.aileron.web.sso.dao;

import java.util.Properties;

import cc.aileron.dao.db.DbConduct;
import cc.aileron.dao.db.DbConnectionManager;
import cc.aileron.dao.db.DbConnectionManagerH2onMemory;
import cc.aileron.dao.db.SqlFileType;
import cc.aileron.dao.db.logger.NullLogger;
import cc.aileron.dao.db.logger.StdoutLogger;
import cc.aileron.template.sql.impl.SqlLogInterface;

/**
 * Dao規約
 * @author Aileron
 *
 */
public class DaoConduct extends DbConduct
{    
    /**
     * debug-flag
     */
    private final boolean isDebug;
    
    /**
     * constractor
     * @param properties
     */
    public DaoConduct(final Properties properties)
    {
        this.isDebug = properties.getProperty("db.debug").equals("true");
    }

    /* (非 Javadoc)
     * @see cc.aileron.dao.db.DbConduct#getConnectionManager()
     */
    public DbConnectionManager getConnectionManager() throws Exception
    {
        return new DbConnectionManagerH2onMemory();
    }

    /* (非 Javadoc)
     * @see cc.aileron.dao.db.DbConduct#getInterface()
     */
    public SqlLogInterface getInterface()
    {
        if(isDebug)
        {
            return new StdoutLogger();
        }
        else
        {
            return new NullLogger();
        }
    }

    /* (非 Javadoc)
     * @see cc.aileron.dao.db.DbConduct#getSqlFileType()
     */
    public SqlFileType getSqlFileType()
    {
        return SqlFileType.SHARED;
    }

    /* (非 Javadoc)
     * @see cc.aileron.dao.db.DbConduct#getTargetPackage()
     */
    public Package getTargetPackage()
    {
        return this.getClass().getPackage();
    }

}
